package cn.iocoder.yudao.module.eval.dal.mysql.question;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.eval.controller.admin.question.vo.EvalQuestionBankPageReqVO;
import cn.iocoder.yudao.module.eval.dal.dataobject.question.EvalQuestionBankDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 题库 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface EvalQuestionBankMapper extends BaseMapperX<EvalQuestionBankDO> {

    default PageResult<EvalQuestionBankDO> selectPage(EvalQuestionBankPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<EvalQuestionBankDO>()
                .likeIfPresent(EvalQuestionBankDO::getBankCode, reqVO.getBankCode())
                .likeIfPresent(EvalQuestionBankDO::getBankName, reqVO.getBankName())
                .eqIfPresent(EvalQuestionBankDO::getCategoryId, reqVO.getCategoryId())
                .likeIfPresent(EvalQuestionBankDO::getProfessionCode, reqVO.getProfessionCode())
                .likeIfPresent(EvalQuestionBankDO::getProfessionName, reqVO.getProfessionName())
                .eqIfPresent(EvalQuestionBankDO::getEvaluationMethod, reqVO.getEvaluationMethod())
                .eqIfPresent(EvalQuestionBankDO::getBankStatus, reqVO.getBankStatus())
                .eqIfPresent(EvalQuestionBankDO::getIsDefault, reqVO.getIsDefault())
                .betweenIfPresent(EvalQuestionBankDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(EvalQuestionBankDO::getId));
    }

    default EvalQuestionBankDO selectByBankCode(String bankCode) {
        return selectOne(EvalQuestionBankDO::getBankCode, bankCode);
    }

    default List<EvalQuestionBankDO> selectListByCategoryId(Long categoryId) {
        return selectList(EvalQuestionBankDO::getCategoryId, categoryId);
    }

    default List<EvalQuestionBankDO> selectListByProfessionCode(String professionCode) {
        return selectList(EvalQuestionBankDO::getProfessionCode, professionCode);
    }

    default List<EvalQuestionBankDO> selectListByEvaluationMethod(String evaluationMethod) {
        return selectList(EvalQuestionBankDO::getEvaluationMethod, evaluationMethod);
    }

    default List<EvalQuestionBankDO> selectListByBankStatus(Integer bankStatus) {
        return selectList(EvalQuestionBankDO::getBankStatus, bankStatus);
    }

    default List<EvalQuestionBankDO> selectListByIsDefault(Boolean isDefault) {
        return selectList(EvalQuestionBankDO::getIsDefault, isDefault);
    }

    default List<EvalQuestionBankDO> selectListByProfessionAndMethod(String professionCode, String evaluationMethod) {
        return selectList(new LambdaQueryWrapperX<EvalQuestionBankDO>()
                .eq(EvalQuestionBankDO::getProfessionCode, professionCode)
                .eq(EvalQuestionBankDO::getEvaluationMethod, evaluationMethod)
                .eq(EvalQuestionBankDO::getBankStatus, 1));
    }

}
